<template>
  <wd-toast />
  <view class="setting-container" :style="{ height: `${windowHeight}px` }">
    <view class="menu-list">
      <view class="list-cell list-cell-arrow" @click="handleToPwd">
        <view class="menu-item-box">
          <view class="iconfont icon-icon-password menu-icon"></view>
          <view>修改密码</view>
        </view>
      </view>
      <!-- <view class="list-cell list-cell-arrow" @click="handleToUpgrade">
        <view class="menu-item-box">
          <view class="iconfont icon-icon-refresh menu-icon"></view>
          <view>检查更新</view>
        </view>
      </view> -->
      <view class="list-cell list-cell-arrow" @click="handleCleanTmp">
        <view class="menu-item-box">
          <view class="iconfont icon-icon-clean menu-icon"></view>
          <view>清理缓存</view>
        </view>
      </view>
    </view>
    <view class="cu-list menu">
      <view class="cu-item item-box">
        <view class="content text-center" @click="handleLogout">
          <text class="text-black">退出登录</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { getAccessToken, setToken, removeToken } from '@/utils/auth'
// import { useStore } from 'vuex'
import { useUserStore } from '@/store/modules/user'
import { useRouter } from 'vue-router'
import { useToast } from 'wot-design-uni'


const toast = useToast()
// 获取系统信息
const windowHeight = ref(uni.getSystemInfoSync().windowHeight)
const store = useUserStore();
const router = useRouter()

// 跳转修改密码
const handleToPwd = () => {
  uni.navigateTo({ url: '/pages/mine/pwd/index' })
}

// 检查更新
const handleToUpgrade = () => {
  uni.showToast({ title: '模块建设中~', icon: 'none' })
}

// 清理缓存
const handleCleanTmp = async () => {
  uni.removeStorageSync('user')
  uni.removeStorageSync('roleRouters') // 删除用户缓存
  uni.removeStorageSync('dict')
  await removeToken()
  toast.success('清除缓存成功');
}

// 退出登录
const handleLogout = () => {
  uni.showModal({
    title: '提示',
    content: '确定注销并退出系统吗？',
    success: (res) => {
      if (res.confirm) {
        store.logout().then(() => {
          uni.reLaunch({ url: '/pages/login/index' })
        })
      }
    }
  })
}
</script>

<style lang="scss" scoped>
.page {
  background-color: #f8f8f8;
}

.item-box {
  background-color: #FFFFFF;
  margin: 30rpx;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  padding: 10rpx;
  border-radius: 8rpx;
  color: #303133;
  font-size: 32rpx;
}
</style>